from httpRequest.httpRequest import HttpRequest
from httpRequest.testcase import RunRequest, Config


class TestMyTestDemo(HttpRequest):
    config = Config("testcase description").base_url("http://erp2.hzb-it.com/").variables(**{"name": "GG"})

    def test_a(self):
        self.TestStep(
            RunRequest("name")
            .post("http://erp2.hzb-it.com/app/common/login")
            .with_headers(**{
                "Host": "erp2.hzb-it.com",  # todo: 引用Host变量
                "Content-Length": "27",  # todo：引用局部变量
                "Accept": "application/json, text/plain, */*",  # todo: 引用Accept变量
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36",
                "Content-Type": "application/x-www-form-urlencoded",
                "Origin": "http://erp2.hzb-it.com",
                "Referer": "http://erp2.hzb-it.com/",
                "Accept-Encoding": "gzip, deflate",
                "Accept-Language": "zh-CN,zh;q=0.9",
                "Connection": "keep-alive",
            })
            .with_data({"username": "admin", "password": "123"})
            .extract()
            .with_jmespath("body.data", "data")
            .validate()
            .assert_equal("status_code", 200)
            .assert_equal("body.errCode", 0)
        )

    def test_b(self):
        self.TestStep(
            RunRequest("name")
            .get("app/common/login")
            .with_headers(**{"a": "b", "token": "$ENV{token}"})
            .with_data({"a": "b", "token": "${data}"})
        )


if __name__ == '__main__':
    TestMyTestDemo()
